<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="/Esquina_da_TI/default.css" rel="stylesheet" type="text/css" media="screen" />
        <title>Relatorio de clientes</title>
    </head>
    <body>
        <center>
            <h1>Relatorio de Clientes</h1>
            <form id="relatorioCliente" name="relatorioCliente" action="" method="post">
                <table border="1">
                    <tr>
                        <th class="relatorio">Codigo</th>
                        <th class="relatorio">Nome</th>                        
                        <th class="relatorio">Cpf</th>
                        <th class="relatorio">Cnpj</th>
                        <th class="relatorio">Razão Social</th>
                        <th class="relatorio">Ativo</th>
                    </tr>                    
                    <?php
                    
                    echo "<tr>";

                    require_once ($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/Dao/Conexao.php');
                    require_once ($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/ClassesBasicas/Privilegio.php');

                    $conexao = new Conexao();

                    $conexao->abrirConexao();

                    //o numero % representa o codigo do privilegio no banco de dados.
                    $query = "SELECT * FROM usuario WHERE privilegio = '5'";

                    $result = $conexao->executarQuery($query);

                    if ($conexao->numeroLinhas($result) == 0) {
                        echo "<td class='relatorio'>&nbsp;</td>";
                        echo "<td class='relatorio'>&nbsp;</td>";
                        echo "<td class='relatorio'>&nbsp;</td>";
                        echo "<td class='relatorio'>&nbsp;</td>";
                        echo "<td class='relatorio'>&nbsp;</td>";
                        echo "<td class='relatorio'>&nbsp;</td>";
                    }else {
                        while($c = mysql_fetch_array($result)) {
                            echo "<td class='relatorio'>".$c['codUsuario']."</td>";
                            echo "<td class='relatorio'>".$c['nome']."</td>";

                            //verificando se o cpf esta preenchido
                            if($c['cpf']) {
                                echo "<td class='relatorio'>".$c['cpf']."</td>";
                            }else {
                                echo "<td class='relatorio'>&nbsp;</td>";
                            }

                            //verificando se o cliente tem algum cnpj
                            if($c['cnpj']) {
                                echo "<td class='relatorio'>".$c['cnpj']."</td>";
                            }else {
                                echo "<td class='relatorio'>&nbsp;</td>";
                            }

                            //verificando se a razão social esta não esta em branco
                            if($c['razaoSocial']) {
                                echo "<td class='relatorio'>".$c['razaoSocial']."</td>";
                            }else {
                                echo "<td class='relatorio'>&nbsp;</td>";
                            }


                            //verificando se o usuario esta ativado
                            if($c['ativo']) {
                                echo "<td class='relatorio'>Ativado</td>";
                            }else {
                                echo "<td class='relatorio'>Inativo</td>";
                            }

                            echo "<td class'relatorio'><a href=\"clienteExcluir.php?codigo=".$c['codUsuario']."\"><img src=\"../images/btn_excluir.jpg\"></a></td>";
                        }
                    }
                    echo "</tr>";

                    ?>
                </table>
            </form>
        </center>
    </body>
</html>
